#include <iostream>
#include <string>
#include <jsoncpp/json/json.h>
int main()
{
    Json::Value root;
    root["x"] = 10;
    root["oper"] = '+';
    root["y"] = 20;
    Json::StreamWriterBuilder wbuilder; //StreamWriterBuilder的工厂
    std::unique_ptr<Json::StreamWriter> writer(wbuilder.newStreamWriter());
    std::stringstream ss;
    writer->write(root,&ss);
    std::cout << ss.str() << std::endl;
    //解析
    Json::Reader reader;
    Json::Value root1;
    // 从字符串获取JSON数据
    bool parsingSuccessful = reader.parse(ss.str(), root1);
    if (!parsingSuccessful)
    {
        // 解析失败， 输出错误信息
        std::cout << "Failed to parse JSON: " << reader.getFormattedErrorMessages() << std::endl;
        return false;
    }
    int x = root1["x"].asInt(); //注意json中的类型需要进行类型检查
    int y = root1["y"].asInt();
    char oper = root1["oper"].asInt();
    std::cout << x << " " << oper << " " << y << std::endl;
}